package com.xiaoKe.zhonghzu.global.tool;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.xiaoKe.zhonghzu.R;


public class ToastUtils {
    private static Context mContext;

    public static void init(Context context) {
        mContext = context;
    }

    // 私有构造函数，防止实例化
    private ToastUtils() {}

    /**
     * 显示短时间的 Toast
     *
     * @param message 要显示的消息
     */
    public static void showShort(String message) {
        Toast toast = new Toast(mContext);
        View view = LayoutInflater.from(mContext).inflate(R.layout.simple_toast, null);
        TextView textView = view.findViewById(R.id.message);
        textView.setText(message);
        view.setBackgroundColor(Color.BLACK);
        textView.setTextColor(Color.WHITE);
        toast.setView(view);
        toast.setDuration(Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }

    /**
     * 显示长时间的 Toast
     *
     * @param message 要显示的消息
     */
    public static void showLong(String message) {
        Toast toast = new Toast(mContext);
        View view = LayoutInflater.from(mContext).inflate(R.layout.simple_toast, null);
        TextView textView = view.findViewById(R.id.message);
        textView.setText(message);
        view.setBackgroundColor(Color.BLACK);
        textView.setTextColor(Color.WHITE);
        toast.setView(view);
        toast.setDuration(Toast.LENGTH_LONG);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }

    /**
     * 显示自定义布局的 Toast
     *
     * @param context 上下文
     * @param layoutId 自定义布局ID
     */
    public static void showCustom(Context context, int layoutId) {
        Toast toast = new Toast(context);
        View view = LayoutInflater.from(context).inflate(layoutId, null);
        view.setBackgroundColor(Color.BLACK);
        toast.setView(view);
        toast.setDuration(Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }
}